<template>
	<view class="content">
		<f-navbar title="银行卡设置" fontColor="#333" fontSize="34" bgColor="#fff">
			<view class="u-flex" slot="left">
				<van-icon name="arrow-left" color="#333" size="20" />
			</view>
		</f-navbar>
		<view class="content_box">
			<view class="content_namebox">
				<view class="content_name">开户行</view>
				<!-- <view class="content_nameR">{{nickname}}</view> -->
				<input :value="bankname" @input="onbankname" type="text" class="phone_input" placeholder-class="place_class"
					placeholder="请输入">
			</view>
			<view class="content_namebox">
				<view class="content_name">用户名</view>
				<!-- <view class="content_nameR">{{nickname}}</view> -->
				<input :value="nickname" @input="onnickname" type="text" class="phone_input" placeholder-class="place_class"
					placeholder="请输入">
			</view>
			<view class="content_namebox">
				<view class="content_name">卡号</view>
				<!-- <view class="content_nameR">{{nickname}}</view> -->
				<input :value="cardid" @input="oncardid" type="text" class="phone_input" placeholder-class="place_class"
					placeholder="请输入">
			</view>
		</view>
		<view class="btnbox" @click="submit">
			保存
		</view>
	</view>
</template>

<script>
	import fNavbar from '@/uni_modules/f-navbar/components/f-navbar/f-navbar.vue';
	import {
		bank,
		getBank
	} from '../../../utils/app.js'
	export default {
		components: {
			fNavbar
		},
		data() {
			return {
				bankname: '',
				nickname:'', 
				cardid:'',
				apiUrl: getApp().globalData.apiUrl,
			}
		},
		onLoad() {
			this.getList()
		},
		methods: {
			// 获取数据
			getList(){
				getBank({
				}).then(res => {
					if(res.code==1){
						this.bankname = res.data.bank_name
						this.nickname = res.data.real_name
						this.cardid = res.data.bank_number
					} else {
						uni.showToast({
							icon:'none',
							title:res.info,
							duration:1000
						})
					}
				})
			},
			// 点击保存
			submit(){
				bank({
					real_name: this.nickname,
					bank_name: this.bankname,
					bank_number: this.cardid
				}).then(res => {
			
					if(res.code==1){
						uni.showToast({
							icon:'success',
							title:res.info,
							duration:1000
						})
						var pages = getCurrentPages();
						var prevPage = pages[pages.length - 2]; //上一个页面
						console.log(prevPage);
						// prevPage.setData({
						//      userdata: {
						//        phonenum:this.phonenum
						//      }
						//    })
						prevPage.$vm.getList(true)
						uni.navigateBack({ //返回
							delta: 1
						})
					} else{
						uni.showToast({
							icon:'none',
							title:res.info,
							duration:1000
						})
					}
				
				})
			},
			
			onbankname(e){
				this.bankname = e.detail.value
			},
			onnickname(e){
				this.nickname = e.detail.value
			},
			oncardid(e){
				this.cardid = e.detail.value
			},
		},
	}
</script>

<style>
	page {
		background: #eee;
	}

	.content_box {
		margin-top: 20rpx;
	}
	.content_namebox {
		width: 94%;
		height: 96rpx;
		display: flex;
		align-items: center;
		justify-content: space-between;
		background: #fff;
		border-top: 1rpx solid #eee;
		margin: 0 auto;
	}
	
	.content_name {
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: 600;
		color: #333333;
		margin-left: 30rpx;
	}
	
	.content_nameR {
		/* display: flex;
		align-items: center; */
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #BBBBBB;
		margin-right: 30rpx;
	}
	.place_class {
		font-size: 28rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #BBBBBB;
	
	}
	.phone_input {
		text-align: right;
		padding-right: 30rpx;
	}
	.btnbox{
		width: 670rpx;
		height: 88rpx;
		background: #EF0E6C;
		border-radius: 44rpx;
		font-size: 36rpx;
		font-family: Hiragino Sans GB;
		font-weight: normal;
		color: #FFFEFE;
		line-height: 88rpx;
		text-align: center;
		margin: 0 auto;
		margin-top: 60rpx;
	}
</style>